package com.tanggh.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.tanggh.entity.User;
import com.tanggh.service.UserService;
import com.tanggh.util.Validator;

public class UserAction extends GenericAction {
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private UserService userService;
	private User user;
	public void setUser(User user) {
		this.user = user;
	}


	@Override
	public String execute() throws Exception {
		/*System.out.println(getString("name"));
		User user = new User();
		user.setUserName("tanggaohong");
		user.setPassword("aaaaaa");
		user.setCompanyName("地产公司");
		user.setMobilePhone("15966669999");
		user.setQq("63419666");
		user.setUserType(1);
		user.setRegisterDate(new Timestamp(new Date().getTime()));
		user.setLatestLoginDate(new Timestamp(new Date().getTime()));
		user.setLatestLoginIp(getIP());
		
		userService.save(user);*/
		try {
			List<User> list = userService.listAll();
			for(User u: list) {
				System.out.println("U:"+u.getEmail());
			}
			System.out.println("userName:"+user.getEmail());
			System.out.println("ok");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public String checkEmail() {
		String email = getString("email");
		if(Validator.isEmpty(email)) {
			write("404");
			return null;
		}
		if(!Validator.isEmail(email)) {
			write("500");
			return null;
		}
		boolean result = userService.checkEmailExist(email);
		if(result) { //存在
			write("100");
			return null;
		}
		write("0"); //不存在,可以注册
		return null;
	}
}
